package com.qiang.demo01;

import javax.xml.crypto.Data;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;
import java.util.Date;

public class Test01 {
    public static void main(String[] args) throws ParseException {

        /*
        比较你和同桌的年纪差多少天？
        比较你和同桌谁的出生时间早?
        如果你可以活99岁，算算你还剩多少天?
        */
        /*String b1 = "2001年12月11日";
        String b2 = "1993年05月20日";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
        Date parse1 = sdf.parse(b1);//解析
        Date parse2 = sdf.parse(b2);//解析
        System.out.println(parse1);
        System.out.println(parse2);

        //时间转换成秒，再转换成天
        long time1 = parse1.getTime();
        long time2 = parse2.getTime();
        System.out.println(time1);
        System.out.println(time2);
        long l = time1 - time2;
        System.out.println(l);

        System.out.println("一共相差天数为：");
        long l1 = l / (24 * 60 * 60 * 1000);
        System.out.println(l1);
        System.out.println("======================");

        //99年的毫秒
        String b3 = "2092年05月20日";
        long time3 = sdf.parse(b3).getTime();
        *//*long ll1 = 99 * 365 * 24 * 60 * 60 * 1000;
        System.out.println(ll1);*//*
        long l2 = System.currentTimeMillis();
        long l3 = time3 - l2;
        long l4 = l3 / (24 * 60 * 60 * 1000);
        System.out.println("还可以活" + l4 + "天");
*/







        /* String s = "2020年11月12日 13:14:15";
        DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm:ss");
        LocalDateTime parse = LocalDateTime.parse(s, pattern);
        System.out.println(parse);*/


/*
=========================
2000年开始到现在，
  你活了多少秒?多少分钟？多少小时？多少天?多少月？多少年？多少周？
  */

//现在的时间，
        //LocalDateTime now = LocalDateTime.now();
        //System.out.println(now);
        //DateTimeFormatter.ofPattern("")
       /* LocalDate of = LocalDate.of(2000, 11, 11);
        LocalDate of1 = LocalDate.of(2020, 11, 11);
        Period between = Period.between(of, of1);
        System.out.println(between);
        int years = between.getYears();
        int months = between.getMonths();
        int days = between.getDays();
        System.out.println(years);
        System.out.println(months);
        System.out.println(days);*/
       /* Period between = Period.between(now, of);
        //LocalDate localDate = of.toLocalDate();
        int years = between.getYears();
        int months = between.getMonths();
        int days = between.getDays();
        System.out.println();*/

        /*LocalDateTime localDateTime1 = LocalDateTime.of(2020, 1, 1, 13, 14, 15);
        LocalDateTime localDateTime2 = LocalDateTime.of(2020, 1, 2, 11, 12, 13);
        System.out.println(localDateTime1);
        System.out.println(localDateTime2);
        Duration bt = Duration.between(localDateTime1, localDateTime2);
        long l = bt.toDays();
        long l1 = bt.toHours();
        System.out.println(l);
        System.out.println(l1);*/





/*
=========================
Date d=new Date();
将以上的d转换为指定格式"xxxx年/xx月/xx日 xx分:xx秒"
1_用SimpleDateFormat实现
2_用JDK8提供的关于新的时间API实现*/

        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年/MM月/dd日 HH时:mm分:ss秒");
        String format = sdf.format(date);
        System.out.println(format);

        LocalDateTime now = LocalDateTime.now();
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy年/MM月/dd日 HH时:mm分:ss秒");

        String format1 = now.format(dtf);
        System.out.println(format1);
/*
=========================
现在有一个字符串"2020年10月10日 10时10分10秒"
将其转换为Date类型

=========================
         */

        String ss = "2020年10月10日 10时10分10秒";
        DateTimeFormatter dtf1 = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH时mm分ss秒");
        LocalDateTime parse = LocalDateTime.parse(ss, dtf1);
        System.out.println(parse);
    }
}
